using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using VOL.Entity.DomainModels;
using SqlSugar;

namespace VOL.demo.Repositories
{
    public partial class unitmodelRepository
    {
        /// <summary>
        /// 获取所有单位下拉选项
        /// </summary>
        /// <returns>单位列表</returns>
        public async Task<List<unitmodel>> GetUnitOptionsAsync()
        {
            return await DbContext.Queryable<unitmodel>()
                .Where(x => x.IsDelete == 0)
                .OrderBy(x => x.Sort)
                .OrderBy(x => x.UnitName)
                .ToListAsync();
        }

        /// <summary>
        /// 根据单位ID获取单位信息
        /// </summary>
        /// <param name="unitId">单位ID</param>
        /// <returns>单位信息</returns>
        public async Task<unitmodel> GetUnitByIdAsync(long unitId)
        {
            return await DbContext.Queryable<unitmodel>()
                .Where(x => x.Id == unitId && x.IsDelete == 0)
                .FirstAsync();
        }
    }
}
